import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface ImState {
    newMessage: Object;
    currentGroupInfo: Object
}

const initialState: ImState = {
    newMessage: {},
    currentGroupInfo: undefined
};

const imSlice = createSlice({
    name: 'im',
    initialState,
    reducers: {
        setNewMessage(state, action) {
            state.newMessage = action.payload.newMessage;
        },
        setCurrentGroupInfo(state, action) {
            state.currentGroupInfo = action.payload.currentGroupInfo;
        },
        clearUser(state) {
            state.name = '';
            state.email = '';
        },
    },
});

export const { setNewMessage, clearUser, setCurrentGroupInfo } = imSlice.actions;
export default imSlice.reducer;
